#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    bool is_letter(char x)
    {
        if (x >= 'a' && x <= 'z' || x >= 'A' && x <= 'Z') return true;
        return false;
    }
    string reverseOnlyLetters(string s) {
        int begin = 0, end = s.size() - 1;
        while (begin < end)
        {
            while (begin < end && !is_letter(s[begin]))
            {
                begin++;
            }

            while (begin < end && !is_letter(s[end]))
            {
                end--;
            }
            swap(s[begin], s[end]);
            begin++; end--;
        }
        return s;

    }
};